package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.service.CourseService;
import com.zr.service.MarkService;

import net.sf.json.JSONObject;

public class UpdateScoreController extends HttpServlet{
	MarkService ms=new MarkService();
	CourseService cs=new CourseService();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String s=req.getParameter("score");
		String cid=req.getParameter("cid");
		int score=Integer.parseInt(s);
		int courseId=Integer.parseInt(cid);
		boolean flag=false;
		PrintWriter pw=resp.getWriter();
		System.out.println(cs.compareAddMarkTime());
		if (cs.compareAddMarkTime()) {
			flag=ms.updateScore(courseId,score);
			pw.write(flag+"");
		}else{
			JSONObject jso=cs.getAddMarkTime();
			pw.write(jso.toString());
		}
		
	}
}
